home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / xulrunner-1.9.0.14 / chrome / comm.jar / content / cookie / cookieAcceptDialog.js next >
Encoding:
Text File  |  2007-03-11  |  7.7 KB  |  190 lines

  1. //@line 36 "/build/buildd/xulrunner-1.9-1.9.0.14+build2+nobinonly/mozilla/toolkit/components/cookie/content/cookieAcceptDialog.js"
  2.  
  3. const nsICookieAcceptDialog = Components.interfaces.nsICookieAcceptDialog;
  4. const nsIDialogParamBlock = Components.interfaces.nsIDialogParamBlock;
  5. const nsICookie = Components.interfaces.nsICookie;
  6. const nsICookiePromptService = Components.interfaces.nsICookiePromptService;
  7.  
  8. var params; 
  9. var cookieBundle;
  10. var gDateService = null;
  11.  
  12. var showDetails = "";
  13. var hideDetails = "";
  14. var detailsAccessKey = "";
  15.  
  16. function onload()
  17. {
  18.   doSetOKCancel(cookieAcceptNormal, cookieDeny, cookieAcceptSession);
  19.  
  20.   var dialog = document.documentElement;
  21.  
  22.   document.getElementById("Button2").collapsed = false;
  23.   
  24.   document.getElementById("ok").label = dialog.getAttribute("acceptLabel");
  25.   document.getElementById("ok").accessKey = dialog.getAttribute("acceptKey");
  26.   document.getElementById("Button2").label = dialog.getAttribute("extra1Label");
  27.   document.getElementById("Button2").accessKey = dialog.getAttribute("extra1Key");
  28.   document.getElementById("cancel").label = dialog.getAttribute("cancelLabel");
  29.   document.getElementById("cancel").accessKey = dialog.getAttribute("cancelKey");
  30.  
  31.   // hook up button icons where implemented
  32.   document.getElementById("ok").setAttribute("icon","accept");
  33.   document.getElementById("cancel").setAttribute("icon","cancel");
  34.   document.getElementById("disclosureButton").setAttribute("icon","properties");
  35.  
  36.   if (!gDateService) {
  37.     const nsScriptableDateFormat_CONTRACTID = "@mozilla.org/intl/scriptabledateformat;1";
  38.     const nsIScriptableDateFormat = Components.interfaces.nsIScriptableDateFormat;
  39.     gDateService = Components.classes[nsScriptableDateFormat_CONTRACTID]
  40.                              .getService(nsIScriptableDateFormat);
  41.   }
  42.  
  43.   cookieBundle = document.getElementById("cookieBundle");
  44.  
  45.   //cache strings
  46.   if (!showDetails) {
  47.     showDetails = cookieBundle.getString('showDetails');
  48.   }
  49.   if (!hideDetails) {
  50.     hideDetails = cookieBundle.getString('hideDetails');
  51.   }
  52.   detailsAccessKey = cookieBundle.getString('detailsAccessKey');
  53.  
  54.   if (document.getElementById('infobox').hidden) {
  55.     document.getElementById('disclosureButton').setAttribute("label",showDetails);
  56.   } else {
  57.     document.getElementById('disclosureButton').setAttribute("label",hideDetails);
  58.   }
  59.   document.getElementById('disclosureButton').setAttribute("accesskey",detailsAccessKey);
  60.  
  61.   if ("arguments" in window && window.arguments.length >= 1 && window.arguments[0]) {
  62.     try {
  63.       params = window.arguments[0].QueryInterface(nsIDialogParamBlock);
  64.       var objects = params.objects;
  65.       var cookie = params.objects.queryElementAt(0,nsICookie);
  66.       
  67.       var cookiesFromHost = params.GetInt(nsICookieAcceptDialog.COOKIESFROMHOST);
  68.  
  69.       var messageFormat;
  70.       if (params.GetInt(nsICookieAcceptDialog.CHANGINGCOOKIE))
  71.         messageFormat = 'permissionToModifyCookie';
  72.       else if (cookiesFromHost > 1)
  73.         messageFormat = 'permissionToSetAnotherCookie';
  74.       else if (cookiesFromHost == 1)
  75.         messageFormat = 'permissionToSetSecondCookie';
  76.       else
  77.         messageFormat = 'permissionToSetACookie';
  78.  
  79.       var hostname = params.GetString(nsICookieAcceptDialog.HOSTNAME);
  80.  
  81.       var messageText;
  82.       if (cookie)
  83.         messageText = cookieBundle.getFormattedString(messageFormat,[hostname, cookiesFromHost]);
  84.       else
  85.         // No cookies means something went wrong. Bring up the dialog anyway
  86.         // to not make the mess worse.
  87.         messageText = cookieBundle.getFormattedString(messageFormat,["",cookiesFromHost]);
  88.  
  89.       var messageParent = document.getElementById("dialogtextbox");
  90.       var messageParagraphs = messageText.split("\n");
  91.  
  92.       // use value for the header, so it doesn't wrap.
  93.       var headerNode = document.getElementById("dialog-header");
  94.       headerNode.setAttribute("value",messageParagraphs[0]);
  95.  
  96.       // use childnodes here, the text can wrap
  97.       for (var i = 1; i < messageParagraphs.length; i++) {
  98.         var descriptionNode = document.createElement("description");
  99.         text = document.createTextNode(messageParagraphs[i]);
  100.         descriptionNode.appendChild(text);
  101.         messageParent.appendChild(descriptionNode);
  102.       }
  103.  
  104.       if (cookie) {
  105.         document.getElementById('ifl_name').setAttribute("value",cookie.name);
  106.         document.getElementById('ifl_value').setAttribute("value",cookie.value);
  107.         document.getElementById('ifl_host').setAttribute("value",cookie.host);
  108.         document.getElementById('ifl_path').setAttribute("value",cookie.path);
  109.         document.getElementById('ifl_isSecure').setAttribute("value",
  110.                                                                  cookie.isSecure ?
  111.                                                                     cookieBundle.getString("forSecureOnly") : cookieBundle.getString("forAnyConnection")
  112.                                                           );
  113.         document.getElementById('ifl_expires').setAttribute("value",GetExpiresString(cookie.expires));
  114.         document.getElementById('ifl_isDomain').setAttribute("value",
  115.                                                                  cookie.isDomain ?
  116.                                                                     cookieBundle.getString("domainColon") : cookieBundle.getString("hostColon")
  117.                                                             );
  118.       }
  119.       // set default result to not accept the cookie
  120.       params.SetInt(nsICookieAcceptDialog.ACCEPT_COOKIE, 0);
  121.       // and to not persist
  122.       params.SetInt(nsICookieAcceptDialog.REMEMBER_DECISION, 0);
  123.     } catch (e) {
  124.     }
  125.   }
  126. }
  127.  
  128. function showhideinfo()
  129. {
  130.   var infobox=document.getElementById('infobox');
  131.  
  132.   if (infobox.hidden) {
  133.     infobox.setAttribute("hidden","false");
  134.     document.getElementById('disclosureButton').setAttribute("label",hideDetails);
  135.   } else {
  136.     infobox.setAttribute("hidden","true");
  137.     document.getElementById('disclosureButton').setAttribute("label",showDetails);
  138.   }
  139.   sizeToContent();
  140. }
  141.  
  142. function cookieAcceptNormal()
  143. {
  144.   // accept the cookie normally
  145.   params.SetInt(nsICookieAcceptDialog.ACCEPT_COOKIE, nsICookiePromptService.ACCEPT_COOKIE); 
  146.   // And remember that when needed
  147.   params.SetInt(nsICookieAcceptDialog.REMEMBER_DECISION, document.getElementById('persistDomainAcceptance').checked);
  148.   window.close();
  149. }
  150.  
  151. function cookieAcceptSession()
  152. {
  153.   // accept for the session only
  154.   params.SetInt(nsICookieAcceptDialog.ACCEPT_COOKIE, nsICookiePromptService.ACCEPT_SESSION_COOKIE);
  155.   // And remember that when needed
  156.   params.SetInt(nsICookieAcceptDialog.REMEMBER_DECISION, document.getElementById('persistDomainAcceptance').checked);
  157.   window.close();
  158. }
  159.  
  160. function cookieDeny()
  161. {
  162.   // say that the cookie was rejected
  163.   params.SetInt(nsICookieAcceptDialog.ACCEPT_COOKIE, nsICookiePromptService.DENY_COOKIE); 
  164.   // And remember that when needed
  165.   params.SetInt(nsICookieAcceptDialog.REMEMBER_DECISION, document.getElementById('persistDomainAcceptance').checked);
  166.   window.close();
  167. }
  168.  
  169. function GetExpiresString(secondsUntilExpires) {
  170.   if (secondsUntilExpires) {
  171.     var date = new Date(1000*secondsUntilExpires);
  172.  
  173.     // if a server manages to set a really long-lived cookie, the dateservice
  174.     // can't cope with it properly, so we'll just return a blank string
  175.     // see bug 238045 for details
  176.     var expiry = "";
  177.     try {
  178.       expiry = gDateService.FormatDateTime("", gDateService.dateFormatLong,
  179.                                            gDateService.timeFormatSeconds, 
  180.                                            date.getFullYear(), date.getMonth()+1, 
  181.                                            date.getDate(), date.getHours(),
  182.                                            date.getMinutes(), date.getSeconds());
  183.     } catch(ex) {
  184.       // do nothing
  185.     }
  186.     return expiry;
  187.   }
  188.   return cookieBundle.getString("atEndOfSession");
  189. }
  190.